//
//  CameraViewController.m
//  carSecretary
//
//  Created by huangliru on 14-9-9.
//  Copyright (c) 2014年 huangliru. All rights reserved.
//

#import "CameraViewController.h"

@interface CameraViewController ()

@end

@implementation CameraViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //创建一个导航栏
    UINavigationBar *bar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 18, 320, 44)];
    //创建一个导航栏集合
    UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:nil];
    //创建一个左边按钮
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleBordered target:self action:@selector(backButton)];
    //设置导航栏内容
    [navigationItem setTitle:@"摄像头"];
    //把导航栏集合添加入导航栏中，设置动画关闭
    [bar pushNavigationItem:navigationItem animated:NO];
    //把左按钮添加入导航栏集合中
    [navigationItem setLeftBarButtonItem:leftButton];
    bar.backgroundColor = [UIColor grayColor];
    [self.view addSubview:bar];
    
    // 选择前置摄像视频按钮
    self.front = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.front.frame = CGRectMake(0, 538, 80, 30);
    self.front.tag = 10;
    self.front.selected = YES;
    if (self.front.selected == YES)
    {
        self.front.backgroundColor = [UIColor grayColor];
    }
    else
    {
        self.front.backgroundColor = [UIColor whiteColor];
    }
    [self.front setTitle:@"前" forState:UIControlStateNormal];
//    self.front.tintColor = [UIColor blackColor];
    [self.front addTarget:self action:@selector(playFront) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.front];
    
    // 选择后置摄像视频按钮
    self.behind = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.behind.frame = CGRectMake(80, 538, 80, 30);
    self.behind.tag = 11;
    [self.behind setTitle:@"后" forState:UIControlStateNormal];
//    self.behind.tintColor = [UIColor blackColor];
    [self.behind addTarget:self action:@selector(playbehind) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.behind];
    
    
    // 选择左置摄像视频按钮
    self.left = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.left.frame = CGRectMake(160, 538, 80, 30);
    self.left.tag = 12;
    [self.left setTitle:@"左" forState:UIControlStateNormal];
//    self.left.tintColor = [UIColor blackColor];
    [self.left addTarget:self action:@selector(playleft) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.left];
    
    // 选择右置摄像视频按钮
    self.right = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.right.frame = CGRectMake(240, 538, 80, 30);
    self.right.tag = 13;
    [self.right setTitle:@"右" forState:UIControlStateNormal];
//    self.right.tintColor = [UIColor blackColor];
    [self.right addTarget:self action:@selector(playright) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.right];
    
    
    // 控制视频播放或暂停按钮
    self.playButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    self.playButton.frame = CGRectMake(10, 505, 30,  30);
    [self.playButton setBackgroundImage:[UIImage imageNamed:@"bfzn_004.png"] forState:UIControlStateNormal];
    [self.playButton addTarget:self action:@selector(playAndPauseBtnPress) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.playButton];
    // 创建视频播放器
    NSURL *url = [NSURL URLWithString:@"http://v.youku.com/player/getRealM3U8/vid/XNDUwNjc4MzA4/type/video.m3u8 "];
    self.moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
    // 设置视频控制器的区域
    [self.moviePlayer.view setFrame:CGRectMake(0, 63, 320, 440)];
    // 准备播放
    [self.moviePlayer prepareToPlay];
    // 设置样式
    [self.moviePlayer setMovieSourceType:MPMovieControlModeDefault];
    // 默认为暂停状态
    [self.moviePlayer pause];
    // 添加到主视图控制器
    [self.view addSubview:self.moviePlayer.view];
}
// 视频播放器
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    
    [self performSelector:@selector(fixStatusBar) withObject:nil afterDelay:0];
    
}
- (void)fixStatusBar {
    
    [[UIApplication sharedApplication] setStatusBarOrientation:[self interfaceOrientation] animated:NO];
    
}
// 播放按钮事件
-(void)playAndPauseBtnPress
{
    self.isPlay = !self.isPlay;
    if (self.isPlay)
    {
        [self.playButton setBackgroundImage:[UIImage imageNamed:@"bfzn_003.png"] forState:UIControlStateNormal];
        [self.moviePlayer play];
    }
    else
    {
        [self.playButton setBackgroundImage:[UIImage imageNamed:@"bfzn_004.png"] forState:UIControlStateNormal];
        [self.moviePlayer pause];
    }
    
}
// 播放前置摄像头视频
-(void)playFront
{
    
}
// 播放后置摄像头视频
-(void)playbehind
{
    
}
// 播放左置摄像头视频
-(void)playleft
{
    
}
// 播放右置摄像头视频
-(void)playright
{
    
}
// 导航栏返回按钮
-(void)backButton
{
    [self dismissViewControllerAnimated:NO completion:nil];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
